package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.domain.clue.CluePoolDO;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.club.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 *
 * @author MrZhao
 * @created 2025-10-13 18:25
 * @description 线索管理Controller
 *
 */
@Slf4j
@RestController
@RequestMapping("/clues")
@SuppressWarnings("all")
public class ClueController {

    @Autowired
    private ClueService clueService;
    @GetMapping("/pool")
    public Result getPool(CluePoolDTO dto){
        PageResult<CluePoolDO> result = clueService.getPool(dto);
        return Result.success(result);
    }
    @LogAnno
    @PutMapping("/false/{id}")
    public Result toFalse(@PathVariable Integer id){
        MarkFalseClueDto markFalse =clueService.toFalse(id);
        return Result.success(markFalse);
    }
    @LogAnno
    @PutMapping("toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }
    //跟进线索
    @LogAnno
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto) {
        // TODO 验证每一个请求都会开辟一条线程池中线程处理
        log.info("=========================Controller 中 方法updateClueInfoById 处理线程名称是：{}",Thread.currentThread().getName());
        clueService.updateClueInfoById(dto);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id){
        ClueVO vo= clueService.getClueInfoById(id);
        return Result.success(vo);
    }
    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }
    @GetMapping
    public Result list(ClueListDTO dto) {
        PageResult<ClueDO> result = clueService.clueList(dto);
        return Result.success(result);
    }
    @LogAnno
    @PostMapping
    public Result addRule(@RequestBody ClueDTO dto){
        clueService.addClue(dto);
        return Result.success();
    }
}
